@extends('Home/Layout/base_login_resgister')

@section('title', '登录页面')
    
@section('main')
    <div class="login-main-wrap">
        <div class="login-main wrapper">
            <div class="login-box">
                <form action="" method="">
                    <div class="box-hd">
                        <span class="tit">用户登录</span>
                        <a href="{{url("/register")}}">注册新账号</a>
                    </div>
                    <label class="txtin-box">
                        <span class="ico user"></span>
                        <input id='checkuser' class="txtin" type="text" name="username" placeholder="用户名" />
                    </label>
                    <label class="txtin-box">
                        <span class="ico pwd"></span>
                        <input id='checkpwd' class="txtin" type="password" name="pwd" placeholder="密码" />
                    </label>
                    <div class="clearfix tool">
                        <a class="find" href="{{url("/forgotpwd")}}">忘记密码？</a>
                    </div>
                    <input class="tj" type="button" value="登&ensp;录" />
                    <div class="other-way clearfix">
                        <a class="item first" href="">
                            <img src="{{asset('Home/img/login/weixin.jpg')}}" alt="" class="ico" />
                            <span class="label">微信</span>
                        </a>
                        <a class="item" href="">
                            <img src="{{asset('Home/img/login/qq.jpg')}}" alt="" class="ico" />
                            <span class="label">微信</span>
                        </a>
                        <a class="item" href="">
                            <img src="{{asset('Home/img/login/sina.jpg')}}" alt="" class="ico" />
                            <span class="label">微信</span>
                        </a>
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection

@section('footer-js')
<script>

        $('.tj').on('click', function () {
            var uname = $('input[name="username"]').val();
            var upwd = $('input[name="pwd"]').val();

        $.axpost(
            'post',
            '{{url("/dologin")}}',
            'name='+uname+'&pwd='+upwd+'&_token={{csrf_token()}}',

            function (data) {
                if (data.status == 1300){

                    layer.msg(data.msg,function(){});

                }

                if (data.status == 1302){

                    layer.msg(data.msg, {icon: 5});
                }

                if (data.status == 1303){

                    layer.msg(data.msg, {
                        icon:4,
                        time: 20000, //20s后自动关闭
                        btn: ['请联系客服']
                    });
                }
                
                if (data.status==1200) {

                    layer.alert(data.msg, {icon:1});
                    location.href = '{{url("/")}}';
                }
            },

           function (tipString) {

                if (tipString.responseText) {
                    var tipObj = JSON.parse(tipString.responseText).errors;
                    //console.log(tipObj);
                   
                   if (tipObj['name']) {

                        layer.tips(tipObj['name'], '#checkuser', {
                            tips:[2, '#FF0000'],
                            tipsMore: true

                        });
                   }

                   if (tipObj['pwd']) {
                        layer.tips(tipObj['pwd'], '#checkpwd', {
                            tips:[2, '#FF0000'],
                            tipsMore: true
                        });
                    }
                }
            }
        );
    });
</script>
@endsection
